package com.changli02.selfdefine.exer1;

import java.util.*;

public class DAO<T> {
    Map<String,T> map = new HashMap<>();

    public DAO() {
    }

    public DAO(Map<String, T> map) {
        this.map = map;
    }

    public void save(String id, T entity){
        if(!map.containsKey(id)){
            map.put(id,entity);
        }
    }
    public T get(String id) {
        return map.get(id);
    }
    public void update(String id,T entity){
        if(map.containsKey(id)){
            map.put(id,entity);
        }
    }
    public List<T> list (){
        Collection<T> coll = map.values();
        List<T> list = new ArrayList(coll);
        return list;
    }
    public void delete(String id){
        map.remove(id);
    }


}
